home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / perl / perl5a1.lha / perl5alpha1 / do / getsockname < prev    next >
Encoding:
Text File  |  1992-08-15  |  832 b   |  46 lines

  1. int
  2. do_getsockname(optype, stab, arglast)
  3. int optype;
  4. STAB *stab;
  5. int *arglast;
  6. {
  7.     register STR **st = stack->ary_array;
  8.     register int sp = arglast[1];
  9.     register STIO *stio;
  10.     int fd;
  11.  
  12.     if (!stab)
  13.     goto nuts;
  14.  
  15.     stio = stab_io(stab);
  16.     if (!stio || !stio->ifp)
  17.     goto nuts;
  18.  
  19.     st[sp] = str_2mortal(Str_new(22,257));
  20.     st[sp]->str_cur = 256;
  21.     st[sp]->str_pok = 1;
  22.     fd = fileno(stio->ifp);
  23.     switch (optype) {
  24.     case O_GETSOCKNAME:
  25.     if (getsockname(fd, st[sp]->str_ptr, (int*)&st[sp]->str_cur) < 0)
  26.         goto nuts2;
  27.     break;
  28.     case O_GETPEERNAME:
  29.     if (getpeername(fd, st[sp]->str_ptr, (int*)&st[sp]->str_cur) < 0)
  30.         goto nuts2;
  31.     break;
  32.     }
  33.     
  34.     return sp;
  35.  
  36. nuts:
  37.     if (dowarn)
  38.     warn("get{sock,peer}name() on closed fd");
  39.     errno = EBADF;
  40. nuts2:
  41.     st[sp] = &str_undef;
  42.     return sp;
  43.  
  44. }
  45.  
  46.